package ab.mes.service.impl;

import ab.mes.entity.orderFQARecords;
import ab.mes.service.orderDetainRecordsService;
import ab.mes.tools.Result;
import ab.mes.tools.orderDetainRecordsConditions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class orderDetainRecordsServiceImpl implements orderDetainRecordsService {
    @Autowired
    private ab.mes.mapper.orderDetainRecordsMapper orderDetainRecordsMapper;

    //查询所有订单扣留记录
    @Override
    public Result selectAll() {
        Result result = new Result();
        result.getMap().put("orderDetainRecords",orderDetainRecordsMapper.selectList(null));
        return result;
    }

    //根据起止日期查询订单扣留记录
    @Override
    public Result select1(orderDetainRecordsConditions conditions) {
        Result result = new Result();
        QueryWrapper<orderFQARecords> wrapper = new QueryWrapper<>();
        //订单编号不为空时，才进行查询
        wrapper.eq(conditions.getOrderNoOrProductionNo()!="","order_No",
                conditions.getOrderNoOrProductionNo());
        wrapper.or();
        //生产序号不为空时，才进行查询
        wrapper.eq(conditions.getOrderNoOrProductionNo()!="","production_No",
                conditions.getOrderNoOrProductionNo());
        //当开始时间不为空时，才进行查询 ge：大于等于
        wrapper.ge(conditions.getStartDate() != null,"handle_Time",
                conditions.getStartDate());
        //当结束时间不为空时，才进行查询 le：小于等于
        wrapper.le(conditions.getEndDate()!=null,"handle_Time",
                conditions.getEndDate());
        List<orderFQARecords> recordsList = orderDetainRecordsMapper.select1(wrapper);
        if(recordsList.size() == 0){
            result.setErrorMessage("无符合条件的信息");
        }else {
            result.getMap().put("orderDetainRecords",recordsList);
        }
        return result;
    }
}
